package functions 
{	import functions.FunctionNode;	/**
	 * @author admin
	 */
	public class SetfFunctionNode extends FunctionNode 
	{
		
		public function SetfFunctionNode()
		{
			funcname = "setf";	
			functiontype = FUNCTION;		}
		
		override public function getValue( args : XML, scope : Object ) : XML
		{
//			trace("In SetfFunctionNode.getValue, args are " + args);
			var returnXML : XML;
			// of course, setf does two very different things.
			// give it a normal varname, and it simply sets that varname in the symboltable.
			// so, since we get unevaluated args,
			// we evaluate the first arg and use that as the varname.
			// fine.
			// however.
			// if the first arg is a list,
			// and that list has a GETF for its first element,
			// then we need to do something quite different.
			//
			// instead of evaluating that GETF,
			// we use its obscure getPositionInList() method
			// to get a numberliteral
			// which is the position in the list
			// which is the SECOND arg to that getf!
			
						
			
			
					
			//let's assume that the first arg is the name of the var
			//simple case: <q>myvarname</q>
			//more complex case: <symbol>pointerToVarName</symbol>
			//  we need a Flash String primitive here.
			
			var varname:String = Evaluator.getLiteral( args.children()[ 0 ]);
	
			// we do *not* need to extract the actual Flash literal from that node
			// in order to assign it to a symbol in the symboltable.
			// in fact, it's a whole lot better and easier if we don't!			
			
			returnXML = args.children()[ 1 ];
//			trace("In SetfFunctionNode, returning " + returnXML.toXMLString());
			Evaluator.setInScope( "symbolvalue" + varname, returnXML, scope );
			return returnXML;
		}
	}}